<?php

namespace App\Http\Controllers\Api\V1\Resources;

use App\Models\BuyerNotice;
use App\Models\SeckillProduct;
use Illuminate\Support\Facades\Redis;
use Illuminate\Http\Resources\Json\JsonResource;

class ProductResource extends JsonResource
{
    public function toArray($request)
    {
    	$resource = $this->resource;
    	
        $data = [
        	
        	'id' => $resource->id,
	        'category_id' => $resource->category_id,
	        'title' => $resource->title,
	        'description' => $resource->description,
	        'recommendation' => $resource->recommendation,
	        'cover_url' => $resource->cover_url,
	        'price_vip' => $resource->price_vip,
	        'sold_count' => (int)$resource->sold_count,
	        'created_at' => (string)$resource->created_at,
	        'updated_at' => (string)$resource->updated_at,
	        'comment_count' => (int)$resource->comment_count,
	        'comment_favor_rate' => (int)$resource->comment_favor_rate,
	        'brand'=> isset($resource->brand) ? $resource->brand->name : '',
	        'origin'=> $resource->origin,
	        'net' => $resource->net,
	        'category' => new CategoryResource($this->category),
	        'attribute_group' => new AttributeGroupResource($this->attributeGroup),
	        'skus' => ProductSkuResource::collection($this->skus),
	        'slides' => ProductSlideResource::collection($this->slides),
	        'images' => ProductImageResource::collection($this->images),
	        'stock' =>  $resource->stock

        ];
        
        return $data;
    }
}
